package com.vote.controllers;

import java.lang.annotation.Annotation;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import net.paoding.rose.web.ControllerInterceptorAdapter;
import net.paoding.rose.web.Invocation;

import com.vote.model.User;
import com.vote.utils.HostHelper;
import com.vote.utils.LoginRequired;

public class LoginRequiredInterceptor extends ControllerInterceptorAdapter {

    @Override
    public Class<? extends Annotation> getRequiredAnnotationClass() {
        return LoginRequired.class;
    }

    @Override
    public Object before(Invocation inv) throws Exception {
        User host = HostHelper.getHost(inv.getRequest());
        if(host == null){
            return "r:login";
        }
        return true;
    }
}